1694A - Creep - CodeForces Solution


greedy implementation *800

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    a, b = map(int, input().split())
    res = ""
    while a != 0 and b != 0:
        res += '10'
        a -= 1
        b -= 1
    res += '0'*a
    res += '1'*b
    print(res)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll sol()
{
   ll a,b,c,z=1;
   cin>>a>>b;
   if(a<b)
   {
       c=b-a;
   }
   else if(b<a)
   {
       c=a-b;
   }
   else
   {
       c=1;
   }
       while(b!=0 || a!=0)
       {
            for(ll i=1;i<=c;i++)
            {
                if(z==1 && b>0)
                {
                    cout<<'1';
                    b--;
                }
                 if(b==0)
                 {
                     z=0;
                     break;
                 }
                 if(c==i)
                 {
                     z=0;
                 }
            }
            for(ll i=1;i<=c;i++)
            {
                if(z==0 && a>0)
                {
                    cout<<'0';
                    a--;
                }
                 if(a==0)
                 {
                     z=1;
                     break;
                 }
                  if(c==i)
                 {
                     z=1;
                 }
            }
            
       }
       cout<<endl;
   
   return 0;

}
int main() {
    ll t;
    cin>>t;
    while(t--)
    {
        ll a=sol();
    }
}


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament